package com.hzhc.controller.wxapp;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.YwOrderService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.YwOrderVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author 功不唐捐
 * @description app委托模块
 * @date 2024-06-19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/app")
public class WxApiYwOrderController extends BaseController {

    private final YwOrderService ywOrderService;

    @Value("${cms.targetUrl}")
    private String targetUrl;

    /**
     * 查询
     */
    @RequestMapping("/getAppOrderList")
    public ResultUtil<List<YwOrderVo>> getOrderList(@RequestBody YwOrderVo vo) {
        Page<YwOrderVo> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
        List<YwOrderVo> vos = ywOrderService.getOrderPage(page, vo);
        return ResultUtil.build(vos,page.getTotal(),page.getPages(),ResultUtilCodeEnum.SUCCESS);
    }


    /**
     * 新增
     */
    @PostMapping("/addAppOrder")
    @SysTemLog(operModul = "班列发运业务新增", operType = "新增", operDesc = "新增班列发运功能", modular = "APP")
    public ResultUtil<T> addAppOrder(@RequestBody YwOrderVo vo) {
        vo.setCreateTime(LocalDateTime.now());
        return ywOrderService.addOrder(vo,targetUrl);
    }

    /**
     * 编辑
     */
    @PostMapping("/updateAppOrder")
    @SysTemLog(operModul = "班列发运业务修改", operType = "修改", operDesc = "修改班列发运功能", modular = "APP")
    public ResultUtil<T> updateAppOrder(@RequestBody YwOrderVo vo) {
        vo.setUpdateTime(LocalDateTime.now());
        return ywOrderService.updateOrder(vo);
    }

    /**
     * 删除
     */
    @RequestMapping("/deleteAppOrder/{id}")
    @SysTemLog(operModul = "班列业务删除", operType = "删除", operDesc = "删除班列功能", modular = "APP")
    public ResultUtil<T> deleteAppOrder(@PathVariable("id") Integer id) {
        return ywOrderService.deleteOrder(id);
    }

    /**
     * 审核
     */
    @PostMapping("/updateAppCheck")
    @SysTemLog(operModul = "班列业务审核", operType = "审核", operDesc = "审核班列功能", modular = "APP")
    public ResultUtil<T> updateAppCheck(HttpServletRequest request, @RequestBody YwOrderVo vo) {
        Long userID = TokenUtil.getUserID(request);
        vo.setUpdateUserId(userID);
        return ywOrderService.updateCheck(vo);
    }

    /**
     * 新增提重委托
     */
    @PostMapping("/addAppTzOrder")
    @SysTemLog(operModul = "班列到达业务新增", operType = "新增", operDesc = "新增班列到达功能", modular = "APP")
    public ResultUtil<T> addAppTzOrder(@RequestBody YwOrderVo vo) {
        vo.setCreateTime(LocalDateTime.now());
        return ywOrderService.addTzOrder(vo);
    }

    /**
     * 编辑提重委托
     */
    @PostMapping("/updateAppTzOrder")
    @SysTemLog(operModul = "班列到达业务修改", operType = "修改", operDesc = "修改班列到达功能", modular = "APP")
    public ResultUtil<T> updateAppTzOrder(@RequestBody YwOrderVo vo) {
        vo.setUpdateTime(LocalDateTime.now());
        return ywOrderService.updateTzOrder(vo);
    }
}
